<?php
$vacancies = $records['vacancies'];

/*
define('ROOT_PATH3', dirname(__FILE__));
$strFilePath = str_replace("\applicant",'',ROOT_PATH3);
$emailContent = CommonFunctions::escapeHtml(file_get_contents($strFilePath.'/mails/applicant-received.htm'));
$emailContent= str_replace('#hrstaffname#',EmpInfo::getFullName($_SESSION['empID']) ,$emailContent );
$emailContent= str_replace('#hrstaffemail#',EmpInfo::getEmpEmail($_SESSION['empID']) ,$emailContent );
*/

$formAction = $_SERVER['PHP_SELF'] . '?recruitcode=Application&action=AddApplicant';

$objAjax = new xajax();
$objAjax->processRequests();

$langList = $records['lang'];
$skillList = $records['skill'];

$picDir = "../../themes/{$styleSheet}/pictures/";
$iconDir = "../../themes/{$styleSheet}/icons/";

$backImg = $picDir . 'btn_back.gif';
$backImgPressed = $picDir . 'btn_back_02.gif';

$saveImg = $picDir . 'btn_save.gif';
$saveImgPressed = $picDir . 'btn_save_02.gif';

$clearImg = $picDir . 'btn_clear.gif';
$clearImgPressed = $picDir . 'btn_clear_02.gif';
define('ROOT_PATH2', dirname(__FILE__));


?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<?php
	$objAjax->printJavascript();
?>
<script>

    function goBack() {
        location.href = "<?php echo "{$_SERVER['PHP_SELF']}?recruitcode=Application&action=List"; ?>";
    }

	function validate() {
		err = false;
		var msg = '<?php echo $lang_Error_PleaseCorrectTheFollowing; ?>\n\n';
		var errors = new Array();

		var fields = new Array("txtFirstName", "txtMiddleName", "txtLastName", "txtStreet1", "txtPhone","txtMobile", "txtEmail","txtQualifications","txtskill","txtlang","txtexperience");

		var fieldNames = new Array('<?php echo $lang_Recruit_ApplicationForm_FirstName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_MiddleName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_LastName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Address;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Phone;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Mobile;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Email;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Qualifications;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Technical_Skill;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Foreign_Languages;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Experiences;?>');
						

		// compulsary fields
		var compFields = new Array(0, 2, 6,  8,9,10);
		var emailFields = new Array();
		emailFields[0] = 6;
		var phoneFields = new Array();
		phoneFields[0] = 4;
		phoneFields[0] =5;
		
		var textFields = new Array();
		textFields[0] = 3;
		//textFields[1] =7;

		// validate compulsary fields
		var numCompFields = compFields.length;
		for (var i = 0; i < numCompFields; i++ ) {
			//alert(numCompFields);
			var fieldNdx = compFields[i];
			var fieldName = fields[fieldNdx];
		    var value = $(fieldName).value.trim();
		    if (value == '') {
				err = true;
				msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecify ?>" + fieldNames[fieldNdx] + "\n";
		    }
		}
		//
		// Only check validation if all compulsary fields have been specified
		//
		if (err == false) {

			// validate email fields
			var numEmailFields = emailFields.length;
			for (var i = 0; i < numEmailFields; i++ ) {
				var fieldNdx = emailFields[i];
				var fieldName = fields[fieldNdx];
			    var value = $(fieldName).value.trim();
			    if (!checkEmail(value)) {
					err = true;
					msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecifyValidEmail ?>" + fieldNames[fieldNdx] + "\n";
			    }
			}

			// validate phone fields
			var numPhoneFields = phoneFields.length;
			for (var i = 0; i < numPhoneFields; i++ ) {
				var fieldNdx = phoneFields[i];
				var fieldName = fields[fieldNdx];
			    var field = $(fieldName);
			    if (!checkPhone(field)) {
					err = true;
					msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecifyValidPhone ?>" + fieldNames[fieldNdx] + "\n";
			    }
			}
			
			// validate text fields
			var numtextFields = textFields.length;
			for (var i = 0; i < numtextFields; i++ ) {
				var fieldNdx =  textFields[i];
				var fieldName = fields[fieldNdx];				
			    var field =  $(fieldName);  
			    if (field.value.length >300) {
					err = true;
					msg += "\t- <?php echo "Please Specify maximum 300 characters for " ?>" + fieldNames[fieldNdx] + "\n";
			    }
			}
		}
		if (err) {
			alert(msg);
			return false;
		} else {
			return true;
		}
	}

    function save() {
		if (validate()) {
        	$('fromJobApplication').submit();
		} else {
			return false;
		}
    }

	function reset() {
		$('fromJobApplication').reset();
	}
	
	function hideLoading() {
		status = $('status');
		status.style.display = 'none';
	}

	function showLoading() {
		status = $('status');
		status.style.display = 'block';
	}

</script>

    <link href="../../themes/<?php echo $styleSheet;?>/css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">@import url("../../themes/<?php echo $styleSheet;?>/css/style.css"); </style>

    <style type="text/css">
    <!--

    label,select,input,textarea {
        display: block;  /* block float the labels to left column, set a width */
        width: 150px;
        float: left;
        margin: 8px 0px 2px 0px; /* set top margin same as form input - textarea etc. elements */
    }
    input[type=checkbox] {
		width: 15px;
		background-color: transparent;
		vertical-align: bottom;
    }

    /* this is needed because otherwise, hidden fields break the alignment of the other fields */
    input[type=hidden] {
        display: none;
        border: none;
        background-color: red;
    }

    label {
        text-align: left;
        width: 110px;
        padding-left: 10px;
    }

    select,input,textarea {
        margin-left: 10x;
    }

    input,textarea {
        padding-left: 4px;
        padding-right: 4px;
    }

    textarea {
        width: 420px;
        height: 30px;
    }

    form {
        min-width: 550px;
        max-width: 770px;
    }

    br {
        clear: left;
    }

    .roundbox {
        margin-top: 10px;
        margin-left: auto;
        margin-right: auto;
        width: 700px;
    }

    body {
    	margin-top: 10px;
        margin-left: auto;
        margin-right: auto;
        width: 780px;
    }

    .roundbox_content {
        padding:5px;
    }

	.hidden {
		display: none;
	}

	.display-block {
		display: block;
	}

	.positionApplyingFor {
        padding-left: 17px;
        padding-top: 10px;
	}
    -->
</style>

<script type="text/javascript" src="../../scripts/tiny_mce/tiny_mce.js"></script>
	<script type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "simple",
		editor_selector : "mceSimple",
		width : "420",
		height:"150"
	});
	</script>
</head>
<body>
	<h2 class="moduleTitle">Input Resume</h2>
	<div id="status" style="float:right;display:none;">
		<image src='<?php echo $iconDir; ?>/loading.gif' width='20' height='20' style="vertical-align: bottom;" >
		<?php echo $lang_Commn_PleaseWait;?>
	</div>
  	<div id="navigation" style="margin:0;">
  		<img title="<?php echo $lang_Common_Back;?>" onMouseOut="this.src='<?php echo $backImg; ?>';"
  			 onMouseOver="this.src='<?php echo $backImgPressed;?>';" src="<?php echo $backImg;?>"
  			 onClick="goBack();">
	</div>
    <?php $message =  isset($_GET['message']) ? $_GET['message'] : null;
    	if (isset($message)) {
			$col_def = CommonFunctions::getCssClassForMessage($message);
			$message = "lang_Common_" . $message;
	?>
	<div class="message">
		<font class="<?php echo $col_def?>" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
			<?php echo (isset($$message)) ? $$message: ""; ?>
		</font>
	</div>
	<?php }	?>
  <div class="roundbox">
  <form name="fromJobApplication" id="fromJobApplication" enctype="multipart/form-data" method="post" action="<?php echo $formAction;?>">
  		 <input type="hidden" id="txtDirectApply" name="txtDirectApply" value="0"/>
  		<label for="txtVacancyId"><span class="error">*</span> <?php echo "Position"; ?></label>
  		<select name="txtVacancyId"  id="txtVacancyId" size="1">
  				<?php foreach($vacancies as $vacancy){ ?>
				<option value="<?php echo $vacancy->getId(); ?>"><?php echo $vacancy->getJobTitle().'-'.$vacancy->getJobTitleName(); ?></option>
				<?php } ?>
		</select>
  		<br/>
		
        
        <label for="txtLastName"><span class="error">*</span> <?php echo $lang_Recruit_ApplicationForm_LastName; ?></label>
        <input type="text" id="txtLastName" name="txtLastName" tabindex="1" >
        
        <label for="txtMiddleName"><?php echo $lang_Recruit_ApplicationForm_MiddleName; ?></label>
        <input type="text" id="txtMiddleName" name="txtMiddleName" tabindex="2" ><br/>
        
		
        <label for="txtFirstName"><span class="error">*</span> <?php echo $lang_Recruit_ApplicationForm_FirstName; ?></label>
        <input type="text" id="txtFirstName" name="txtFirstName" tabindex="3" ><br/>
        
        
		<label for="txtMobile"> <?php echo $lang_Recruit_ApplicationForm_Mobile; ?></label>
        <input type="text" id="txtMobile" name="txtMobile" tabindex="4" >
		
		<label for="txtEmail"> <span class="error">*</span><?php echo $lang_Recruit_ApplicationForm_Email; ?></label>
        <input type="text" id="txtEmail" name="txtEmail" tabindex="5" ><br/>

		<label for="txtStreet1"><?php echo $lang_Recruit_ApplicationForm_Address; ?></label>
        <textarea id="txtStreet1" name="txtStreet1" tabindex="6" ></textarea><br/><br/>
        
        <label for="txtskill"><span class="error">*</span> <?php echo $lang_Recruit_ApplicationForm_Technical_Skill; ?></label>         
        <select name="txtskill[]"  id="txtskill" size="4" multiple="multiple" style="overflow:scroll;">
  				<?php foreach($skillList as $skill){ ?>
				<option value="<?php echo $skill[0]; ?>"><?php echo $skill[1]; ?></option>
				<?php } ?>
		</select> 
		
        <label for="txtlang"><span class="error">*</span> <?php echo $lang_Recruit_ApplicationForm_Foreign_Languages; ?></label>
        <select name="txtlang[]"  id="txtlang" size="4" multiple="multiple" style="overflow: auto;">
  				<?php foreach($langList as $lang){ ?>
				<option value="<?php echo $lang[0]; ?>"><?php echo $lang[1]; ?></option>
				<?php } ?>
		</select> <br/>
		
		<label for="txtexperience"><span class="error">*</span> <?php echo $lang_Recruit_ApplicationForm_Experiences; ?></label>
		 <select name="txtexperience"  id="txtexperience" size="1" style="overflow: auto;">
  				<?php for($j=0;$j<10;$j++){ ?>
				<option value="<?php echo $j; ?>"><?php echo $j." years "; ?></option>
				<?php } ?>
				<option value="<?php echo 10; ?>"><?php echo ">= 10 years "; ?></option>
		</select> <br/>

        <label for="txtResume"><span class="error">&nbsp;</span> <?php echo $lang_Recruit_ApplicationForm_Resume_Attachment; ?></label>
        <input id="txtResume" name="txtResume"  type="FILE" tabindex="11"/>  <br/>
        
         <label for="txtQualifications"><?php echo $lang_Recruit_ApplicationForm_Qualifications; ?></label>
        <textarea name="txtQualifications" id="txtQualifications" class="mceSimple" ><?php echo (isset($txtQualifications)) ? $txtQualifications : ''; ?></textarea><br/>
        	
        <!-- 
        <label for="txtEmailContent"><?php echo "Email content"; ?></label>
        <textarea name="txtEmailContent" id="txtEmailContent" class="mceSimple" ><?php //echo $emailContent; ?></textarea><br/>
        
        <label for="txtsendmail"><span class="error">&nbsp;</span> <?php echo "Email to candidate"; ?></label>
        <input type="checkbox" id="txtsendmail" name="txtsendmail" tabindex="12" >
        <br/>
         -->
        
        <div align="left">
            <img onClick="save();" id="saveBtn"
				onMouseOut="this.src='<?php echo $saveImg;?>';"
            	onMouseOver="this.src='<?php echo $saveImgPressed;?>';"
            	src="<?php echo $saveImg;?>">
			<!-- 
			<img onClick="reset(); id="resetBtn"
				onMouseOut="this.src='<?php echo $clearImg;?>';"
            	onMouseOver="this.src='<?php echo $clearImgPressed;?>';"
            	src="<?php echo $clearImg;?>">
            	 -->
        </div>
	</form>
    </div>
    <script type="text/javascript">
        <!--
        	if (document.getElementById && document.createElement) {
   	 			initOctopus();
   	 			$('txtLastName').focus();
			}
        -->
    </script>

    <div id="notice"><?php echo preg_replace('/#star/', '<span class="error">*</span>', $lang_Commn_RequiredFieldMark); ?>.</div>
</body>
</html>
